//
//  IsSameTree.swift
//  LeetCodeSummary
//
//  Created by 彭西西 on 2020/8/8.
//  Copyright © 2020 WangYonghe. All rights reserved.
//  100.相同的树

import UIKit

class IsSameTree: NSObject {
    //100.相同的树
    func isSameTree(_ p: TreeNode?, _ q: TreeNode?) -> Bool {
        if p == nil && q == nil {
            return true
        }
        
        if p == nil || q == nil{
            return false
        }
        
        guard p?.val == q?.val else {
            return false
        }
        
        return self.isSameTree(p?.left, q?.left) && self.isSameTree(p?.right, q?.right)
    }
}
